<%@page language="java" pageEncoding="UTF-8"%>
<%@page import="java.util.Enumeration"%>
<%@page import="com.xybean.dao.page.Page"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String url = request.getParameter("url");
	if (url == null) {
		url = (String) request.getAttribute("currentURL");
	}
	Enumeration en = request.getParameterNames();
	Page p = (Page) request.getAttribute("page");
	String urlp = "";
	int num = p.getCurrentPage();
	while (en.hasMoreElements()) {
		Object next = en.nextElement();
		if (!next.equals("url") && !next.equals("currentPage")) {//当next中的值不等于url也不等于currentPage时
			String parm = request.getParameter(next.toString());
			if (parm != null)
				urlp += "&" + next + "=" + parm;//增加分页调回请求的属性(‘&’)
		}
	}
%>
<label style="font-size: 12px; color: black;">
	当前第
	<s:property value="#request.page.getCurrentPage()" />
	/
	<s:property value="#request.page.getPageCount()" />
	总记录数：
	<s:property value="#request.page.getRecordCount()" />
</label>
<s:if
	test="#request.page.getCurrentPage()!=1&&#request.page.recordCount>0">
	<%
		out.write("<a href='" + url + "?currentPage=" + 1 + urlp + "'>"
					+ "首页</a> ");
	%>
</s:if>
<s:else>
	<%
		out.write("<a href='javascript:void();'>首页</a> ");
	%>
</s:else>
<s:if test="#request.page.hasPrevious()">
	<%
		int prepage = num - 1;
			out.write("<a href='" + url + "?currentPage=" + prepage + urlp
					+ "'>" + "上一页</a> ");
	%>
</s:if>
<s:else>
	<%
		out.write("<a href='javascript:void();'>上一页</a> ");
	%>
</s:else>
<%
	int totalDuan = (p.getPageCount() - 1) / 10 + 1;//总段数
	int currentDuan = (p.getCurrentPage() - 1) / 10 + 1;//当前段数
	if (currentDuan > 1) {//如果当前段数并且不是第一段
		String pu = url + "?currentPage=" + ((currentDuan - 1) * 10)
				+ urlp;
		out.write("<a href='" + pu + "'>...</a> ");
	}
	//中间从当前段的第一页开始打印
	int start = (currentDuan - 1) * 10 + 1;
	int end = start + 10;
	if (currentDuan == totalDuan) {//当前段就是最后一段
		end = start + p.getPageCount() - (currentDuan - 1) * 10;
	}
	for (int i = start; i < end; i++) {
		String outUrl;
		outUrl = url + "?currentPage=" + i + urlp;
		if (i == p.getCurrentPage()) {
			out.write(" " + i + " ");
		} else {
			out.write("<a href='" + outUrl + "'>" + i + "</a> ");
		}
	}

	if (totalDuan > 1 && currentDuan != totalDuan) {//如果当前段数并且不是最后一段
		String au = url + "?currentPage=" + (currentDuan * 10 + 1)
				+ urlp;
		out.write("<a href='" + au + "'>...</a> ");
	}
%>
<s:if test="#request.page.hasNext()">
	<%
		int nextpage = num + 1;
			out.write("<a href='" + url + "?currentPage=" + nextpage + urlp
					+ "'>" + "下一页</a> ");
	%>
</s:if>
<s:else>
	<%
		out.write("<a href='javascript:void();'>下一页</a> ");
	%>
</s:else>
<s:if
	test="#request.page.getCurrentPage()!=#request.page.getPageCount()&&#request.page.getPageCount()!=0">
	<%
		out.write("<a href='" + url + "?currentPage="
					+ p.getPageCount() + urlp + "'>" + "尾页</a> ");
	%>
</s:if>
<s:else>
	<%
		out.write("<a href='javascript:void();'>尾页</a> ");
	%>
</s:else>
